#include "stdafx.h"
#include "TunerControl.h"
#include "FreqToNote.h"
#include "AudioSampler.h"

//define note constants
#define A		1
#define ASHARP	2
#define B		3
#define C		4
#define CSHARP	5
#define D		6
#define DSHARP	7
#define E		8
#define F		9
#define FSHARP	10
#define G		11
#define GSHARP	12

//define constants for graphic lines
#define PIXEL1	30
#define PIXEL2	91
#define PIXEL3	152
#define PIXEL4	213
#define PIXEL5	274

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;

TunerControl::TunerControl(System::Windows::Forms::Form * form, System::Resources::ResourceManager * resources,
			System::Windows::Forms::Label * welcomeLabel, System::Windows::Forms::Button * goToTuner,
			System::Windows::Forms::Button * goToMetronome)
{
	//set pointers to main menu components
	welcomeLabel_ = welcomeLabel;
	goToTunerButton_ = goToTuner;
	goToMetronomeButton_ = goToMetronome;
	
	//initialize targets
	note1Target_ = ASHARP;
	note2Target_ = B;
	note4Target_ = CSHARP;
	note5Target_ = D;
	noteGoal_ = C;
	freq_ = 0;
	
	//initialize tuner to off
	shouldRun_ = false;
	
	//initialize drawing pens
	red_ = new Pen(Color::Red, 3);
	green_ = new Pen(Color::Green, 3);
	
	//create all tuner mode components
	tunerBackButton_ = new System::Windows::Forms::Button();
	tunerSettingsLabel_ = new System::Windows::Forms::Label();
	aButton_ = new System::Windows::Forms::RadioButton();
	aSharpButton_ = new System::Windows::Forms::RadioButton();
	bButton_ = new System::Windows::Forms::RadioButton();
	noteSelectBox_ = new System::Windows::Forms::GroupBox();
	fSharpButton_ = new System::Windows::Forms::RadioButton();
	cSharpButton_ = new System::Windows::Forms::RadioButton();
	dButton_ = new System::Windows::Forms::RadioButton();
	dSharpButton_ = new System::Windows::Forms::RadioButton();
	eButton_ = new System::Windows::Forms::RadioButton();
	fButton_ = new System::Windows::Forms::RadioButton();
	cButton_ = new System::Windows::Forms::RadioButton();
	gSharpButton_ = new System::Windows::Forms::RadioButton();
	gButton_ = new System::Windows::Forms::RadioButton();
	targetLabel_ = new System::Windows::Forms::Label();
	startTunerButton_ = new System::Windows::Forms::Button();
	backToTunerButton_ = new System::Windows::Forms::Button();
	graphics_ = new System::Windows::Forms::PictureBox();
	note1Label_ = new System::Windows::Forms::Label();
	note2Label_ = new System::Windows::Forms::Label();
	note3Label_ = new System::Windows::Forms::Label();
	note4Label_ = new System::Windows::Forms::Label();
	note5Label_ = new System::Windows::Forms::Label();
	noteSelectBox_->SuspendLayout();
	
	// tunerBackButton
	tunerBackButton_->Font = new System::Drawing::Font(S"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	tunerBackButton_->Location = System::Drawing::Point(472, 8);
	tunerBackButton_->Name = S"tunerBackButton_";
	tunerBackButton_->Size = System::Drawing::Size(112, 23);
	tunerBackButton_->TabIndex = 0;
	tunerBackButton_->Text = S"Back to Main Menu";
	tunerBackButton_->Click += new System::EventHandler(this, loadMainMenu);
	
	// tunerSettingsLabel
	tunerSettingsLabel_->Font = new System::Drawing::Font(S"Arial", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	tunerSettingsLabel_->Location = System::Drawing::Point(188, 56);
	tunerSettingsLabel_->Name = S"tunerSettingsLabel_";
	tunerSettingsLabel_->Size = System::Drawing::Size(216, 32);
	tunerSettingsLabel_->TabIndex = 1;
	tunerSettingsLabel_->Text = S"Choose Tuner Settings";
	// aButton
	aButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	aButton_->Location = System::Drawing::Point(152, 88);
	aButton_->Name = S"aButton_";
	aButton_->Size = System::Drawing::Size(64, 24);
	aButton_->TabIndex = 2;
	aButton_->Text = S"A";
	aButton_->Click += new System::EventHandler(this, setA);
	
	// aSharpButton
	aSharpButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	aSharpButton_->Location = System::Drawing::Point(152, 112);
	aSharpButton_->Name = S"aSharpButton_";
	aSharpButton_->Size = System::Drawing::Size(64, 24);
	aSharpButton_->TabIndex = 4;
	aSharpButton_->Text = S"A#/Bb";
	aSharpButton_->Click += new System::EventHandler(this, setASharp);
	
	// bButton
	bButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	bButton_->Location = System::Drawing::Point(152, 136);
	bButton_->Name = S"bButton_";
	bButton_->Size = System::Drawing::Size(64, 24);
	bButton_->TabIndex = 5;
	bButton_->Text = S"B";
	bButton_->Click += new System::EventHandler(this, setB);
	
	// noteSelectBox
	//add note selection components to the box
	noteSelectBox_->Controls->Add(fSharpButton_);
	noteSelectBox_->Controls->Add(cSharpButton_);
	noteSelectBox_->Controls->Add(dButton_);
	noteSelectBox_->Controls->Add(dSharpButton_);
	noteSelectBox_->Controls->Add(eButton_);
	noteSelectBox_->Controls->Add(fButton_);
	noteSelectBox_->Controls->Add(cButton_);
	noteSelectBox_->Controls->Add(aSharpButton_);
	noteSelectBox_->Controls->Add(gSharpButton_);
	noteSelectBox_->Controls->Add(bButton_);
	noteSelectBox_->Controls->Add(gButton_);
	noteSelectBox_->Controls->Add(aButton_);
	noteSelectBox_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	noteSelectBox_->Location = System::Drawing::Point(172, 104);
	noteSelectBox_->Name = S"noteSelectBox_";
	noteSelectBox_->Size = System::Drawing::Size(248, 168);
	noteSelectBox_->TabIndex = 6;
	noteSelectBox_->TabStop = false;
	noteSelectBox_->Text = S"Choose note";
	
	// fSharpButton
	fSharpButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	fSharpButton_->Location = System::Drawing::Point(152, 16);
	fSharpButton_->Name = S"fSharpButton_";
	fSharpButton_->Size = System::Drawing::Size(64, 24);
	fSharpButton_->TabIndex = 12;
	fSharpButton_->Text = S"F#/Gb";
	fSharpButton_->Click += new System::EventHandler(this, setFSharp);
	
	// cSharpButton
	cSharpButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	cSharpButton_->Location = System::Drawing::Point(48, 40);
	cSharpButton_->Name = S"cSharpButton_";
	cSharpButton_->Size = System::Drawing::Size(64, 24);
	cSharpButton_->TabIndex = 7;
	cSharpButton_->Text = S"C#/Db";
	cSharpButton_->Click += new System::EventHandler(this, setCSharp);
	
	// dButton
	dButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	dButton_->Location = System::Drawing::Point(48, 64);
	dButton_->Name = S"dButton_";
	dButton_->Size = System::Drawing::Size(64, 24);
	dButton_->TabIndex = 8;
	dButton_->Text = S"D";
	dButton_->Click += new System::EventHandler(this, setD);
	
	// dSharpButton
	dSharpButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	dSharpButton_->Location = System::Drawing::Point(48, 88);
	dSharpButton_->Name = S"dSharpButton_";
	dSharpButton_->Size = System::Drawing::Size(64, 24);
	dSharpButton_->TabIndex = 9;
	dSharpButton_->Text = S"D#/Eb";
	dSharpButton_->Click += new System::EventHandler(this, setDSharp);
	
	// eButton
	eButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	eButton_->Location = System::Drawing::Point(48, 112);
	eButton_->Name = S"eButton_";
	eButton_->Size = System::Drawing::Size(64, 24);
	eButton_->TabIndex = 10;
	eButton_->Text = S"E";
	eButton_->Click += new System::EventHandler(this, setE);
	
	// fButton
	fButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	fButton_->Location = System::Drawing::Point(48, 136);
	fButton_->Name = S"fButton_";
	fButton_->Size = System::Drawing::Size(64, 24);
	fButton_->TabIndex = 11;
	fButton_->Text = S"F";
	fButton_->Click += new System::EventHandler(this, setF);
	
	// cButton
	cButton_->Checked = true;
	cButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	cButton_->Location = System::Drawing::Point(48, 16);
	cButton_->Name = S"cButton_";
	cButton_->Size = System::Drawing::Size(64, 24);
	cButton_->TabIndex = 6;
	cButton_->TabStop = true;
	cButton_->Text = S"C";
	cButton_->Click += new System::EventHandler(this, setC);
	
	// gSharpButton
	gSharpButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	gSharpButton_->Location = System::Drawing::Point(152, 64);
	gSharpButton_->Name = S"gSharpButton_";
	gSharpButton_->Size = System::Drawing::Size(64, 24);
	gSharpButton_->TabIndex = 14;
	gSharpButton_->Text = S"G#/Ab";
	gSharpButton_->Click += new System::EventHandler(this, setGSharp);
	
	// gButton
	gButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	gButton_->Location = System::Drawing::Point(152, 40);
	gButton_->Name = S"gButton_";
	gButton_->Size = System::Drawing::Size(64, 24);
	gButton_->TabIndex = 13;
	gButton_->Text = S"G";
	gButton_->Click += new System::EventHandler(this, setG);
	
	// targetLabel
	targetLabel_->Font = new System::Drawing::Font(S"Arial", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	targetLabel_->Location = System::Drawing::Point(200, 344);
	targetLabel_->Name = S"targetLabel_";
	targetLabel_->Size = System::Drawing::Size(192, 48);
	targetLabel_->TabIndex = 7;
	targetLabel_->Text = S"Target: C";
	targetLabel_->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
	
	// startTuner
	startTunerButton_->Font = new System::Drawing::Font(S"Arial", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	startTunerButton_->Location = System::Drawing::Point(448, 368);
	startTunerButton_->Name = S"startTunerButton_";
	startTunerButton_->Size = System::Drawing::Size(75, 32);
	startTunerButton_->TabIndex = 8;
	startTunerButton_->Text = S"Start!";
	startTunerButton_->Click += new System::EventHandler(this, goToGraphics);
	
	// backToTunerButton
	backToTunerButton_->Font = new System::Drawing::Font(S"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	backToTunerButton_->Location = System::Drawing::Point(488, 408);
	backToTunerButton_->Name = S"backToTunerButton_";
	backToTunerButton_->Size = System::Drawing::Size(80, 40);
	backToTunerButton_->TabIndex = 12;
	backToTunerButton_->Text = S"Change options";
	backToTunerButton_->Click += new System::EventHandler(this, backToTuner);
	
	// graphics
	graphics_->BackColor = System::Drawing::Color::White;
	graphics_->BackgroundImage = (__try_cast<System::Drawing::Image * >(resources->GetObject(S"graphics.BackgroundImage")));
	graphics_->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
	graphics_->Location = System::Drawing::Point(46, 64);
	graphics_->Name = S"graphics_";
	graphics_->Size = System::Drawing::Size(500, 305);
	graphics_->TabIndex = 14;
	graphics_->TabStop = false;
	graphics_->Paint += new System::Windows::Forms::PaintEventHandler(this, drawGraphics);
	
	// note1
	note1Label_->Font = new System::Drawing::Font(S"Arial", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	note1Label_->Location = System::Drawing::Point(8, 88);
	note1Label_->Name = S"note1Label_";
	note1Label_->Size = System::Drawing::Size(35, 23);
	note1Label_->TabIndex = 15;
	note1Label_->Text = S"Nb";
	note1Label_->TextAlign = System::Drawing::ContentAlignment::TopRight;
	
	// note5
	note5Label_->Font = new System::Drawing::Font(S"Arial", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	note5Label_->Location = System::Drawing::Point(8, 326);
	note5Label_->Name = S"note5Label_";
	note5Label_->Size = System::Drawing::Size(35, 23);
	note5Label_->TabIndex = 16;
	note5Label_->Text = S"Nb";
	note5Label_->TextAlign = System::Drawing::ContentAlignment::TopRight;
	
	// note2
	note2Label_->Font = new System::Drawing::Font(S"Arial", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	note2Label_->Location = System::Drawing::Point(8, 145);
	note2Label_->Name = S"note2Label_";
	note2Label_->Size = System::Drawing::Size(35, 23);
	note2Label_->TabIndex = 17;
	note2Label_->Text = S"Nb";
	note2Label_->TextAlign = System::Drawing::ContentAlignment::TopRight;
	
	// note3
	note3Label_->Font = new System::Drawing::Font(S"Arial", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	note3Label_->Location = System::Drawing::Point(8, 205);
	note3Label_->Name = S"note3Label_";
	note3Label_->Size = System::Drawing::Size(35, 23);
	note3Label_->TabIndex = 18;
	note3Label_->Text = S"Nb";
	note3Label_->TextAlign = System::Drawing::ContentAlignment::TopRight;
	
	// note4
	note4Label_->Font = new System::Drawing::Font(S"Arial", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
	note4Label_->Location = System::Drawing::Point(8, 266);
	note4Label_->Name = S"note4Label_";
	note4Label_->Size = System::Drawing::Size(35, 23);
	note4Label_->TabIndex = 19;
	note4Label_->Text = S"Nb";
	note4Label_->TextAlign = System::Drawing::ContentAlignment::TopRight;

	//add all components to main app form
	form->Controls->Add(note4Label_);
	form->Controls->Add(note3Label_);
	form->Controls->Add(note2Label_);
	form->Controls->Add(note5Label_);
	form->Controls->Add(note1Label_);
	form->Controls->Add(graphics_);
	form->Controls->Add(backToTunerButton_);
	form->Controls->Add(noteSelectBox_);
	form->Controls->Add(tunerBackButton_);
	form->Controls->Add(tunerSettingsLabel_);
	form->Controls->Add(targetLabel_);
	form->Controls->Add(startTunerButton_);

	//initially, hide all tuner mode components
	hideSelect();
	hideGraphics();
	noteSelectBox_->ResumeLayout(false);
}

void TunerControl::hideSelect()
{
	//hide components of note selection
	tunerSettingsLabel_->Hide();
	tunerBackButton_->Hide();
	noteSelectBox_->Hide();
	targetLabel_->Hide();
	startTunerButton_->Hide();
}

void TunerControl::showSelect()
{
	//show components of note selection
	tunerSettingsLabel_->Show();
	tunerBackButton_->Show();
	noteSelectBox_->Show();
	targetLabel_->Show();
	startTunerButton_->Show();
}

void TunerControl::hideGraphics()
{
	//hide components of graphics
	backToTunerButton_->Hide();
	graphics_->Hide();
	note1Label_->Hide();
	note2Label_->Hide();
	note3Label_->Hide();
	note4Label_->Hide();
	note5Label_->Hide();
}

void TunerControl::showGraphics()
{
	//show all components of graphics
	updateNoteLabels();
	backToTunerButton_->Show();
	graphics_->Show();
	note1Label_->Show();
	note2Label_->Show();
	note3Label_->Show();
	note4Label_->Show();
	note5Label_->Show();
}


//methods called by each note selection button when clicked, one for each possible target note
void TunerControl::setC(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = C;
	targetLabel_->Text = S"Target: C";
}

void TunerControl::setCSharp(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = CSHARP;
	targetLabel_->Text = S"Target: C#/Db";
}

void TunerControl::setD(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = D;
	targetLabel_->Text = S"Target: D";
}

void TunerControl::setDSharp(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = DSHARP;
	targetLabel_->Text = S"Target: D#/Eb";
}

void TunerControl::setE(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = E;
	targetLabel_->Text = S"Target: E";
}

void TunerControl::setF(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = F;
	targetLabel_->Text = S"Target: F";
}

void TunerControl::setFSharp(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = FSHARP;
	targetLabel_->Text = S"Target: F#/Gb";
}

void TunerControl::setG(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = G;
	targetLabel_->Text = S"Target: G";
}

void TunerControl::setGSharp(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = GSHARP;
	targetLabel_->Text = S"Target: G#/Ab";
}

void TunerControl::setA(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = A;
	targetLabel_->Text = S"Target: A";
}

void TunerControl::setASharp(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = ASHARP;
	targetLabel_->Text = S"Target: A#/Bb";
}

void TunerControl::setB(System::Object * sender, System::EventArgs * e)
{
	noteGoal_ = B;
	targetLabel_->Text = S"Target: B";
}



void TunerControl::loadMainMenu(System::Object *  sender, System::EventArgs *  e)
{
	hideSelect(); //hide the select screen (the only screen from which the main menu can be reached in tuner mode)
	
	//show the main menu components
	welcomeLabel_->Show();
	goToTunerButton_->Show();
	goToMetronomeButton_->Show();
}

void TunerControl::goToGraphics(System::Object *  sender, System::EventArgs *  e)
{
	hideSelect(); //hide the note selection objects
	showGraphics(); //load the graphics
	
	//when loading graphics, start the tuner
	shouldRun_ = true;
	
	//as long as their is not already a thread running
	if(!thread_ || (thread_ && !thread_->IsAlive))
	{
		//create the thread and run it
		ThreadStart *myThreadDelegate = new ThreadStart(this, getFrequency);
		thread_ = new Thread(myThreadDelegate);
		thread_->IsBackground = true;
		thread_->Start();
	}
}


void TunerControl::backToTuner(System::Object *  sender, System::EventArgs *  e)
{
	shouldRun_ = false; //leaving graphics mode, stop audio collection
	hideGraphics();
	showSelect();
}

//function used by thread
void TunerControl::getFrequency()
{
	//create an AudioSampler object to handle audio and initialize it to handle tuner functions
	AudioSampler sampler;
	shouldRun_ = sampler.prepareTuner();

	//as long as tuner should be running
	while(shouldRun_)
	{
		//get the current frequency
		freq_ = sampler.getFrequency();
		
		//refresh the graphics screen
		graphics_->Refresh();
	}

	//when tuner should no longer be running, stop tuner mode in the AudioSampler before the thread dies
	sampler.stopTuner();
}


//function called by refreshing graphics
void TunerControl::drawGraphics(System::Object *  sender, System::Windows::Forms::PaintEventArgs *  e)
{
	//only draw something if the frequency is greater than 0
	if(freq_ > 0)
	{
		//create a FreqToNote object to handle converting frequencies to note names
		FreqToNote processor;
		processor.setFreq((double) freq_);
		
		//get the note name, as defined by note constants
		int note = processor.getNote();
		
		//get the normalized distance the actual frequency is away from the note, rounded to the nearest int and standardized
		//to a 0 to 30 scale to coordinate with the pixel distances
		int diff = (int) floor((processor.getDifference() * 3)+0.5);
		
		//if the note name matches any of the targets that can be drawn, then draw the appropriate line

		if( note == note1Target_ )
		{
			e->Graphics->DrawLine(red_, 0,PIXEL1-diff,500,PIXEL1-diff);
		}
		else if ( note == note2Target_ )
		{
			e->Graphics->DrawLine(red_, 0,PIXEL2-diff,500,PIXEL2-diff);
		}
		else if ( note == noteGoal_ )
		{
			if( Math::Abs(diff) < 6)
			{
				e->Graphics->DrawLine(green_, 0,PIXEL3-diff,500,PIXEL3-diff);
			}
			else
			{
				e->Graphics->DrawLine(red_, 0,PIXEL3-diff,500,PIXEL3-diff);
			}
		}
		else if ( note == note4Target_ )
		{
			e->Graphics->DrawLine(red_, 0,PIXEL4-diff,500,PIXEL4-diff);
		}
		else if ( note == note5Target_ )
		{
			e->Graphics->DrawLine(red_, 0,PIXEL5-diff,500,PIXEL5-diff);
		}
	}
}

void TunerControl::updateNoteLabels()
{
	//switch on target note, change labels on graphics and note target variables accordingly
	switch( noteGoal_ )
	{
		case A:
			//set the text next to the graphics, only showing the two nearest notes to the targets in either direction
			note5Label_->Text = S"G";
			note4Label_->Text = S"G#";
			note3Label_->Text = S"A";
			note2Label_->Text = S"A#";
			note1Label_->Text = S"B";
			
			//update the target variables to reflect this
			note5Target_ = G;
			note4Target_ = GSHARP;
			note2Target_ = ASHARP;
			note1Target_ = B;
			break;
		case ASHARP:
			note5Label_->Text = S"G#";
			note4Label_->Text = S"A";
			note3Label_->Text = S"A#";
			note2Label_->Text = S"B";
			note1Label_->Text = S"C";
			note5Target_ = GSHARP;
			note4Target_ = A;
			note2Target_ = B;
			note1Target_ = C;
			break;
		case B:
			note5Label_->Text = S"A";
			note4Label_->Text = S"A#";
			note3Label_->Text = S"B";
			note2Label_->Text = S"C";
			note1Label_->Text = S"C#";
			note5Target_ = A;
			note4Target_ = ASHARP;
			note2Target_ = C;
			note1Target_ = CSHARP;
			break;
		case C:
			note5Label_->Text = S"A#";
			note4Label_->Text = S"B";
			note3Label_->Text = S"C";
			note2Label_->Text = S"C#";
			note1Label_->Text = S"D";
			note5Target_ = ASHARP;
			note4Target_ = B;
			note2Target_ = CSHARP;
			note1Target_ = D;
			break;
		case CSHARP:
			note5Label_->Text = S"B";
			note4Label_->Text = S"C";
			note3Label_->Text = S"C#";
			note2Label_->Text = S"D";
			note1Label_->Text = S"D#";
			note5Target_ = B;
			note4Target_ = C;
			note2Target_ = D;
			note1Target_ = DSHARP;
			break;
		case D:
			note5Label_->Text = S"C";
			note4Label_->Text = S"C#";
			note3Label_->Text = S"D";
			note2Label_->Text = S"D#";
			note1Label_->Text = S"E";
			note5Target_ = C;
			note4Target_ = CSHARP;
			note2Target_ = DSHARP;
			note1Target_ = E;
			break;
		case DSHARP:
			note5Label_->Text = S"C#";
			note4Label_->Text = S"D";
			note3Label_->Text = S"D#";
			note2Label_->Text = S"E";
			note1Label_->Text = S"F";
			note5Target_ = CSHARP;
			note4Target_ = D;
			note2Target_ = E;
			note1Target_ = F;
			break;
		case E:
			note5Label_->Text = S"D";
			note4Label_->Text = S"D#";
			note3Label_->Text = S"E";
			note2Label_->Text = S"F";
			note1Label_->Text = S"F#";
			note5Target_ = D;
			note4Target_ = DSHARP;
			note2Target_ = F;
			note1Target_ = FSHARP;
			break;
		case F:
			note5Label_->Text = S"D#";
			note4Label_->Text = S"E";
			note3Label_->Text = S"F";
			note2Label_->Text = S"F#";
			note1Label_->Text = S"G";
			note5Target_ = DSHARP;
			note4Target_ = E;
			note2Target_ = FSHARP;
			note1Target_ = G;
			break;
		case FSHARP:
			note5Label_->Text = S"E";
			note4Label_->Text = S"F";
			note3Label_->Text = S"F#";
			note2Label_->Text = S"G";
			note1Label_->Text = S"G#";
			note5Target_ = E;
			note4Target_ = F;
			note2Target_ = G;
			note1Target_ = GSHARP;
			break;
		case G:
			note5Label_->Text = S"F";
			note4Label_->Text = S"F#";
			note3Label_->Text = S"G";
			note2Label_->Text = S"G#";
			note1Label_->Text = S"A";
			note5Target_ = F;
			note4Target_ = FSHARP;
			note2Target_ = GSHARP;
			note1Target_ = A;
			break;
		case GSHARP:
			note5Label_->Text = S"F#";
			note4Label_->Text = S"G";
			note3Label_->Text = S"G#";
			note2Label_->Text = S"A";
			note1Label_->Text = S"A#";
			note5Target_ = FSHARP;
			note4Target_ = G;
			note2Target_ = A;
			note1Target_ = ASHARP;
			break;
		default: //if an error has occurred and noteGoal is set incorrectly, default to blank labels
			note5Label_->Text = S"";
			note4Label_->Text = S"";
			note3Label_->Text = S"";
			note2Label_->Text = S"";
			note1Label_->Text = S"";
	}
}